刘工修改后的订单报表.sql 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. USE [DYBBERPDB]
  2. GO
  3. IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_OrderReport]'))
  4. DROP VIEW [dbo].[BView_OrderReport]
  5. GO
  6. CREATE VIEW [dbo].[BView_OrderReport]
  7. AS
  8. SELECT tb_ErpOrder.ID,dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, tb_ErpOrderDigital.Ordv_ViceNumber,
  9. dbo.tb_ErpOrder.Ord_Class, Ord_Type, Ord_OrderClass,Ordv_DigitalNumber,
  10. CASE Ord_SinceOrderNumber WHEN '' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号,
  11. dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型,
  12. Cus_Name AS 客户姓名,
  13. Cus_Name_py AS 客户拼音,
  14. Cus_Sex_cs AS 客户性别,
  15. Cus_Telephone AS 客户电话,
  16. [Age_String] AS 年龄,
  17. [Age_Day] AS 天,
  18. [Age_Year] AS 年,
  19. dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别,
  20. dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源,
  21. dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称,
  22. dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格,
  23. (select stuff((select ',' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人,
  24. dbo.fn_ChineseToSpell((select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,''))) as 接单人拼音,
  25. (case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '' end) as 拍摄名称,
  26. (select stuff((select ',' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '' group by Ordpg_Photographer for xml path('')),1,1,'')) as 摄影师,
  27. (select stuff((select ',' + dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_MakeupArtist!= '' group by Ordpg_MakeupArtist for xml path('')),1,1,'')) as 化妆师,
  28. (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_PhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄时间,
  29. (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = '2') > 0 then '拍摄中'
  30. else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = '1') > 0 then 'OK' else '未拍' end end) AS 拍照状态,
  31. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital.Ordv_EarlyRepairName) AS 初修师,
  32. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_EarlyRepairTime)) AS 初修时间,
  33. dbo.fn_CheckOrderEarlyRepairStatus(tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态,
  34. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital.Ordv_FilmSelectionName) AS 选片师,
  35. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_FilmSelectionTime)) AS 选片时间,
  36. dbo.fn_CheckOrderFilmSelectionStatus(tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态,
  37. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师,
  38. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计时间,
  39. dbo.fn_CheckOrderDesignerStatus(tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态,
  40. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital.Ordv_RefinementName) AS 精修师,
  41. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修时间,
  42. dbo.fn_CheckOrderRefinementStatus(tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态,
  43. dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师,
  44. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计时间,
  45. dbo.fn_CheckOrderLookDesignStatus(tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态,
  46. tb_ErpOrderDigital.Ordv_LookDesignClaim AS 看设计要求,
  47. [dbo].[fun_GetPickupStatusStatus]([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],[dbo].[Vw_OrderProductPickupView].productCount) AS 取件状态,
  48. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_PickupTime)) AS 取件日期,
  49. dbo.tb_ErpOrder.Ord_Remark AS 备注,
  50. dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrder.Ord_CreateName) AS 录入员,
  51. dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ord_CreateDateTime)) AS 下单日期,
  52. Ord_CreateDateTime AS 下单日期查询,
  53. (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount
  54. FROM
  55. dbo.tb_ErpOrder LEFT JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = tb_ErpOrderDigital.Ordv_Number
  56. left join [dbo].[Vw_OrderProductPickupView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_OrderProductPickupView].OPlist_ViceNumber
  57. left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber
  58. where CONVERT(int,Ord_Type) < 3
  59. GO